package org.jackysoft.entity;

import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Type;
import org.jackysoft.annotations.OptionalText;
import org.jackysoft.entity.AbstractEntity;
import org.jackysoft.util.SecurityGrade;
import org.joda.time.DateTime;

import com.google.common.collect.Lists;

/**
 * 公司年度合同
 * */
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true, dynamicInsert = true)
public class Contract extends AbstractEntity {

	
	private static final long serialVersionUID = 7002757843179454196L;
	private SecurityGrade security = SecurityGrade.秘密;
	private ContractClient client;
	private DateTime dueDate;	
	private String remark;	
	private String name;
	private Double amount;
	private Collection<ContractItem> contractItems = Lists.newArrayList();
	
	
	public Contract() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	public Contract(String id, String name,DateTime dueDate) {
		super();
		this.dueDate = dueDate;
		this.name = name;
		this.id = id;
	}

	public SecurityGrade getSecurity() {
		return security;
	}
	
	@Type(type = "jodatime")
	public DateTime getDueDate() {
		return dueDate;
	}
	public String getRemark() {
		return remark;
	}
	public void setSecurity(SecurityGrade security) {
		this.security = security;
	}
	
	public void setDueDate(DateTime dueDate) {
		this.dueDate = dueDate;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}

	@OneToMany(fetch=FetchType.EAGER)
	@Cascade({CascadeType.ALL,CascadeType.DELETE,CascadeType.SAVE_UPDATE})
	public Collection<ContractItem> getContractItems() {
		return contractItems;
	}

	public void setContractItems(Collection<ContractItem> contractItems) {
		this.contractItems = contractItems;
	}

	@OptionalText
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToOne
	public ContractClient getClient() {
		return client;
	}

	public void setClient(ContractClient client) {
		this.client = client;
	}

	/**
	 * 合同总金额
	 * */
	@Transient
	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}	
}